package com.crb.crm.manage.excel.listener;

import com.crb.crm.manage.excel.ExcelTemplate;
import com.crb.crm.manage.excel.model.TemplateModel;
import com.crb.crm.manage.pojo.biz.Template;
import com.crb.crm.manage.service.biz.TemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * Package: com.crb.crm.manage.excel
 * Description：
 * Author: huangjian
 * Date:  2020/9/4 17:07
 * Modified By:
 * @author huangjian
 */
@Slf4j
@Component
class TemplateExcelListener extends BaseExcelListener<TemplateModel> {

    @Resource
    private TemplateService service;

    @Override
    protected void validData(TemplateModel templateModel, ValidResult validResult) {

    }

    @Override
    public void saveData(List<TemplateModel> list) {
        list.forEach(templateModel -> {
            Template template=new Template();
            template.setName(templateModel.getName());
            template.setCode(templateModel.getCode());
            template.setContent(templateModel.getContent());
            service.setTemplate(template);
        });
    }


    @Override
    public ExcelTemplate support() {
        return ExcelTemplate.TEMPLATE;
    }
}
